﻿
using System.Collections.Generic;
using ColorTools;

namespace DevelopersToolbox {
    public class ColorTheory {
        public static IList<DevColor> Compimentary(DevColor color) {
            IList<DevColor> results = new List<DevColor>();
            results.Add(color);

            int hue = color.Hue + DevColor.HLSMAX / 2;
            while (hue > DevColor.HLSMAX) hue -= DevColor.HLSMAX;
            results.Add(DevColor.FromHLS(hue, color.Sat, color.Lum));

            return results;
        }

        public static IList<DevColor> Monocromatic(DevColor color) {
            IList<DevColor> results = new List<DevColor>();
            results.Add(color);

            // color 1
            int hue = color.Hue;
            int sat = color.Sat;
            int lum = color.Lum - 72;
            if (lum < 0) lum = 0;
            results.Add(DevColor.FromHLS(hue, sat, lum));

            // color 2
            hue = color.Hue;
            sat = color.Sat;
            lum = color.Lum + 72;
            if (lum > DevColor.HLSMAX) lum = DevColor.HLSMAX;
            results.Add(DevColor.FromHLS(hue, sat, lum));

            // color 3
            hue = color.Hue + 68;
            sat = 0;
            lum = color.Lum;
            if (hue > DevColor.HLSMAX) hue -= DevColor.HLSMAX;
            results.Add(DevColor.FromHLS(hue, sat, lum));

            return results;
        }

        public static IList<DevColor> Analogous(DevColor color) {
            IList<DevColor> results = new List<DevColor>();
            results.Add(color);

            // color 1
            int hue = color.Hue - 13;
            int sat = color.Sat;
            int lum = color.Lum;
            if (hue < 0) hue += DevColor.HLSMAX;
            results.Add(DevColor.FromHLS(hue, sat, lum));

            // color 2
            hue = color.Hue + 13;
            sat = color.Sat;
            lum = color.Lum;
            while (hue > DevColor.HLSMAX) hue -= DevColor.HLSMAX;
            results.Add(DevColor.FromHLS(hue, sat, lum));

            // color 3
            hue = color.Hue;
            sat = color.Sat;
            lum = color.Lum + 48;
            while (sat < 0) sat = 0;
            results.Add(DevColor.FromHLS(hue, sat, lum));

            // color 4
            hue = color.Hue + 68;
            sat = 0;
            lum = color.Lum;
            if (hue > DevColor.HLSMAX) hue -= DevColor.HLSMAX;
            results.Add(DevColor.FromHLS(hue, sat, lum));

            return results;
        }

        public static IList<DevColor> Triadic(DevColor color) {
            IList<DevColor> results = new List<DevColor>();
            results.Add(color);

            // color 1
            int hue = color.Hue + 80;
            int sat = color.Sat;
            int lum = color.Lum;
            if (hue > DevColor.HLSMAX) hue -= DevColor.HLSMAX;
            results.Add(DevColor.FromHLS(hue, sat, lum));

            // color 2
            hue = color.Hue + 160;
            sat = color.Sat;
            lum = color.Lum;
            if (hue > DevColor.HLSMAX) hue -= DevColor.HLSMAX;
            results.Add(DevColor.FromHLS(hue, sat, lum));

            return results;
        }

        public static IList<DevColor> Tetradic(DevColor color) {
            IList<DevColor> results = new List<DevColor>();
            results.Add(color);

            // color 1
            int hue = color.Hue + 61;
            int sat = color.Sat;
            int lum = color.Lum;
            if (hue > DevColor.HLSMAX) hue -= DevColor.HLSMAX;
            results.Add(DevColor.FromHLS(hue, sat, lum));

            // color 2
            hue = color.Hue + 122;
            sat = color.Sat;
            lum = color.Lum;
            if (hue > DevColor.HLSMAX) hue -= DevColor.HLSMAX;
            results.Add(DevColor.FromHLS(hue, sat, lum));

            // color 3
            hue = color.Hue + 183;
            sat = color.Sat;
            lum = color.Lum;
            if (hue > DevColor.HLSMAX) hue -= DevColor.HLSMAX;
            results.Add(DevColor.FromHLS(hue, sat, lum));

            return results;
        }

        public static IList<DevColor> SplitComplimentary(DevColor color) {
            IList<DevColor> results = new List<DevColor>();
            results.Add(color);

            // color 1
            int hue = color.Hue + 13;
            int sat = color.Sat;
            int lum = color.Lum;
            if (hue > DevColor.HLSMAX) hue -= DevColor.HLSMAX;
            results.Add(DevColor.FromHLS(hue, sat, lum));

            // color 2
            hue = color.Hue + 100;
            sat = color.Sat;
            lum = color.Lum;
            if (hue > DevColor.HLSMAX) hue -= DevColor.HLSMAX;
            results.Add(DevColor.FromHLS(hue, sat, lum));

            // color 3
            hue = color.Hue - 100;
            sat = color.Sat;
            lum = color.Lum;
            if (hue < 0) hue += DevColor.HLSMAX;
            results.Add(DevColor.FromHLS(hue, sat, lum));

            // color 4
            hue = color.Hue + 68;
            sat = 0;
            lum = color.Lum;
            if (hue > DevColor.HLSMAX) hue -= DevColor.HLSMAX;
            results.Add(DevColor.FromHLS(hue, sat, lum));

            return results;
        }
    }
}
